#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution
{
public:
    static int findPoisonedDuration(vector<int>& timeSeries, int duration)
    {
        int ret = 0;
        for(int i=0; i<timeSeries.size(); i++)
        {
            if(i==timeSeries.size()-1)
            {
                ret += duration;
                break;
            }
            int x = timeSeries[i+1] - timeSeries[i];
            if(x >= duration)
            {
                ret += duration;
            }
            else
            {
                ret += x;
            }
        }
        return ret;
    }
};
